﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace MiniScrum.Models
{
    public class Task
    {
        public int Id { get; set; }
        [Required(ErrorMessage = "Tasks require a name. ")]
        public string Name { get; set; }
        public string Details { get; set; }
        public DateTime? CompletedDate { get; set; }
        public DateTime CreatedDate { get; set; }
        public DateTime? DeletedDate { get; set; }

        public Task()
        {
            CompletedDate = null;
            DeletedDate = null;
        }

        public static void Create(Task task)
        {
            MiniScrum.Models.User user = (System.Threading.Thread.CurrentPrincipal as MiniScrum.Models.User);
            using (var db = new MiniScrumDB())
            {
                task.CreatedDate = DateTime.Now.Date;
                db.Users.Attach(user);
                user.Tasks.Add(task);
                db.SaveChanges();
            }
        }
    }
}